<!documentTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<title>用户资料</title>
		<script src="../js/mui.min.js"></script>
		<link href="../css/mui.min.css" rel="stylesheet" />
	</head>
	<body>
		<header class="mui-bar mui-bar-nav">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 class="mui-title">用户详细资料</h1>
		</header>
		<div class="mui-content">
			<form class="mui-input-group">
				<div class="mui-input-row">
					<label>用户名</label>
				<input type="text" class="mui-input-clear" id="username" disabled>
				</div>
				<div class="mui-input-row">
					<label>性别</label>
					<div>
					<div class="mui-radio" style="float: left;"><label>男</label><input id="male" class="gender" name="gender" type="radio"></div>
					<div class="mui-radio" style="float: left;"><label>女</label><input id="female" class="gender" name="gender" type="radio"></div>
					</div>
				</div>
				<div class="mui-input-row">
					<label>城市</label>
				<input type="text" class="mui-input-clear" id="city" placeholder="请输入城市">
				</div>
				<div class="mui-input-row">
					<label>省份</label>
				<input type="text" class="mui-input-clear" id="province" placeholder="请输入省份">
				</div>
				<div class="mui-input-row">
					<label>电话</label>
				<input type="text" class="mui-input-clear" id="userTel" placeholder="请输入联系电话">
				</div>
				<div class="mui-button-row">
					<button type="button" onclick="updateProfile();" class="mui-btn mui-btn-primary" >更改</button>
					<button type="button" onclick="cancel();" class="mui-btn mui-btn-danger" >返回</button>
				</div>
			</form>
			<div style="height:44px;"></div>
		</div>
		
		<script>
			mui.init();
			
			var userName = localStorage.getItem('userName');
			var userGender = localStorage.getItem('userGender');
			var userCity = localStorage.getItem('userCity');
			var userProvince = localStorage.getItem('userProvince');
			var userTel = localStorage.getItem('userTel');
			document.getElementById('username').value = userName + '（不可更改）';
			document.getElementById('city').value = userCity;
			document.getElementById('province').value = userProvince;
			document.getElementById('userTel').value = userTel;
			if(userGender == '1' || userGender == '男')
			{
				document.getElementById("male").checked = true
				document.getElementById("female").checked = false
			}
						 
			if(userGender == '0' ||userGender == '女')
			{
				document.getElementById("female").checked = true
				document.getElementById("male").checked = false
			}
	
			function updateProfile(){
				userCity = document.getElementById('city').value;
				userProvince = document.getElementById('province').value;
				userTel = document.getElementById('userTel').value;
				if(document.getElementById("male").checked)
				{
					userGender = '1'
				}
							 
				if(document.getElementById("female").checked)
				{
					userGender = '0'
				}
				if(userGender == '' || userCity == '' || userProvince == '' || userTel == ''){
					mui.toast('资料项不能为空');
					return;
				}
				var url = localStorage.getItem('remoteAddress') + '/api/updateUserProfile';
				mui.post(url,{
					userName: userName,
					gender: userGender,
					city: userCity,
					province: userProvince,
					userTel: userTel
				},function(data){
					var data = data.data;
					//服务器返回响应，根据响应结果，分析是否登录成功；
					var updateSuccess = data.updateSuccess;
					//alert(updateSuccess);
					if(updateSuccess == '1'){
						mui.toast('资料更新成功');
					}else{
						mui.toast('资料更新失败，网络错误');
						
					}
				},'json'
				);
				plus.webview.close('profilePage');
			}
			
			function cancel(){
				plus.webview.close('profilePage');
			}
			
		</script>
	</body>
</html>
